﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Xml;

using Landscape.Members;

namespace Landscape.Tests {
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class RendererTest : DefaultTest {
        private TestContext testContextInstance;
        public TestContext TestContext {
            get {
                return testContextInstance;
            }
            set {
                testContextInstance = value;
            }
        }

        [TestMethod]
        public void RenderTemplateToString() {
            var doc = new XmlDocument();
            string result = Landscape.Renderer.Render("BasicTemplate", "<root/>");
            Debug.Assert(!string.IsNullOrEmpty(result));
            Debug.Print("Output: " + result);
        }
        [TestMethod]
        public void RenderNestedTemplateToString() {
            var doc = new XmlDocument();
            string result = Landscape.Renderer.Render("BasicNestedTemplate", "<root/>");
            Debug.Assert(!string.IsNullOrEmpty(result));
            Debug.Print("Output: " + result);
        }
        [TestMethod]
        public void RenderWidget() {
            var doc = new XmlDocument();
            string result = Landscape.Renderer.RenderWidget("BasicWidget", "<root/>", "", new Dictionary<string, object>() { 
                {"param", "OK"}
            });
            Debug.Assert(!string.IsNullOrEmpty(result));
            Debug.Print("Output: " + result);
        }
        [TestMethod]
        public void RenderNestedWidget() {
            var doc = new XmlDocument();
            string result = Landscape.Renderer.RenderWidget("NestedWidget", "<root/>", "", new Dictionary<string, object>() { 
                {"param", "OK"}
            });
            Debug.Assert(!string.IsNullOrEmpty(result));
            Debug.Print("Output: " + result);
        }
        [TestMethod]
        public void RenderInlineExpression() {
            InlineExpression expr = new InlineExpression() {
                DataSource = "<ok/>",
                OutputMethod = Landscape.Context.xslOutputMethod,
                DisableOutputEscaping = true,
                XPath = "local-name(/ok)"
            };
            string result =expr.Compile();
            Debug.Assert(!string.IsNullOrEmpty(result));
            Debug.Assert(result == "ok");
        }
    }
}
